/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.ldu.util;

import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 *
 * @author THEKING
 */
public class Translate {

    public static byte[] ObjectToByte(Object obj){
        byte[] buffer = null;
        try{
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            ObjectOutputStream oo = new ObjectOutputStream(bo);
            oo.writeObject(obj);
            buffer = bo.toByteArray();
            oo.close();
        }catch(IOException ex){
            ex.printStackTrace();
        }
        return buffer;
    }

    public static Object ByteToObject(byte[] buffer){
        Object obj = null;
        try{
            ByteArrayInputStream bi = new ByteArrayInputStream(buffer);
            ObjectInputStream oi = new ObjectInputStream(bi);
            obj = oi.readObject();
            oi.close();
        }catch(IOException | ClassNotFoundException ex){
            ex.printStackTrace();
        }
        return obj;
    }

    //转换时间
    public static String stampToDate(Date date) {
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        String dateString = simpleDateFormat.format(date);
        return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.SIMPLIFIED_CHINESE).format(date);
    }

}
